// irCle.cpp: implementation of the CirCle class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "fxtool.h"

#include <stdlib.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <d3dx9.h>
#include <D3D9.h>

#include "dxutil.h"
#include "d3dutil.h"
#include "d3dfont.h"
#include "D3DEnumeration.h"
#include "DXUtil.h"
#include "D3DEnumeration.h"
#include "D3DSettings.h"

//#include "D3DFile.h"
#include "D3DFont.h"
#include "D3DUtil.h"
#include "DXUtil.h"
#include <AniContainer.h>
#include "ToolCamera.h"
#include <AniContainer.h>
#include "Effect.h"
#include <AniContainer.h>
#include "FXDialog.h"
#include <AniContainer.h>
#include "D3dModel.h"
#include "D3dAddon.h"
#include "VShadowVolume.h"
#include "TerrainMask.h"
#include "ToolApp.h"
#include "irCle.h"

extern ToolApp* g_Draw;

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
struct CIRVERT
{
	D3DXVECTOR3 pos;
	DWORD color;
};

CirCle::CirCle()
{
	D3DXMATRIX mat;
	D3DXMatrixRotationY(&mat,D3DXToRadian( 20));
	D3DXVECTOR3 first(1,0,0);
	D3DXMatrixIdentity(&world);
    g_Draw->m_pd3dDevice->CreateVertexBuffer( 19*sizeof(CIRVERT),
                                                       D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, 0,
                                                       D3DPOOL_DEFAULT, &vert, NULL )  ;
	CIRVERT *m_pVertices;
	vert->Lock( 0, 0, (VOID**)&m_pVertices, 0 );//target
	float angle=0.0f;
	while(angle<=360.0f)
	{
		m_pVertices->pos=first;
		m_pVertices->pos.y=0.1f;
		m_pVertices->color=0xffffffff;
		angle+=20.0f;
		D3DXVec3TransformCoord(&first,&first,&mat);
		m_pVertices++;
	}
	vert->Unlock();
}

CirCle::~CirCle()
{

}

void CirCle::Render(float scale)
{
						g_Draw->m_pd3dDevice->SetTexture(0,NULL);												
//						g_Draw->m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
//						g_Draw->m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
						g_Draw->m_pd3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_WIREFRAME);

						D3DXMatrixScaling(&world,scale,scale,scale);
						g_Draw->m_pd3dDevice->SetTransform(D3DTS_WORLD,&world);
						g_Draw->m_pd3dDevice->SetFVF( D3DFVF_XYZ);
						g_Draw->m_pd3dDevice->SetVertexShader(NULL);
						g_Draw->m_pd3dDevice->SetStreamSource( 0, vert, 0,sizeof(CIRVERT) );
						g_Draw->m_pd3dDevice->DrawPrimitive( D3DPT_LINESTRIP, 0, 18 );
						g_Draw->m_pd3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );

//						g_Draw->m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
//						g_Draw->m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_DISABLE);

}
